﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Text;


namespace Group16.Class_Library
{
    public class Invoice
    {
        private string _invoiceCode;
        private DateTime _dateMade;
        private int _total;
        public string InvoiceCode
        {
            get { return _invoiceCode; }
            set { _invoiceCode = value; }
        }
        public DateTime DateMade
        {
            get { return _dateMade; }
            set { _dateMade = value; }
        }
        public int Total
        {
            get { return _total; }
            set { _total = value; }
        }
        public void LogData()
        {
            try
            {
                string comText = "Insert Into Invoice Values('" + InvoiceCode + "','" + DateMade.ToShortDateString() + "','" + Total + "')";
                DataBaseInteraction.ExecuteCommand(comText, 1);
            }
            catch (SqlException se)
            {
                MessageBox.Show("Unable to insertdata into Invoice table" + se.Message);
            }
            finally
            {
                DataBaseInteraction.Connection.Close();
            }
        }
        static public string GetInvoiceCode()
        {
            try
            {
                string comText = "Select Count(InvoiceCode) from Invoice";
                return DataBaseInteraction.ExecuteCommand(comText, 3).ToString();
            }
            catch (SqlException se)
            {
                MessageBox.Show("Can not Get InvoiceCode " + se.Message);
            }
            finally
            {
                DataBaseInteraction.Connection.Close();
            }
            return null;
        }
    }
}
